// -----------------------------------------------------------------------
//  <copyright file="ResourceOutDto.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2025 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2025/1/6 23:07</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Authorization.Domain.Entities;

namespace DaprPlus.Authorization.Application.Queries;

[MapFrom(typeof(Resource))]
public class ResourceOutDto
{
    public long Id { get; set; }
    public required string Name { get; set; }
    public required string Code { get; set; }
    public string? Description { get; set; }
    public required string ServiceName { get; set; }
    public ResourceType Type { get; set; }
    public ResourceAccessType AccessType { get; set; }
    public bool IsSystem { get; set; }
    public bool IsLocked { get; set; }
    public DateTime CreatedTime { get; set; }
    public string? MetadataJson { private get; set; }

    public Dictionary<string, object> Metadata =>
        string.IsNullOrEmpty(MetadataJson)
            ? []
            : MetadataJson.FromTextJson<Dictionary<string, object>>()!;

    /// <summary>
    /// 获取或设置 允许的操作列表JSON字符串
    /// </summary>
    public string? AllowedOperationsJson { get; set; }

    public ResourceOperation[] AllowedOperations => string.IsNullOrEmpty(AllowedOperationsJson)
        ? []
        : AllowedOperationsJson!.FromTextJson<ResourceOperation[]>()!;
}
